#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/un.h>
#define path_socket_unix "/home/utn_so/miSocketUnix"
#define SOCKET_MAX_BUFFER 512


void enviarDatos(int);



int main(int argc, char **argv) {

if (fork() == 0){

    //conecta y recibe e imprime SERVIDOR
    execv("/home/utn_so/hola.exe",0);
}
else{

    //conecta y envia cliente

/*char buff1[SOCKET_MAX_BUFFER] = "RASPINTI PUTOOOOOO\n";
char buff2[SOCKET_MAX_BUFFER] = "NOSSA NOSSA ASIM VOCE ME MATA 146546 \n";*/

    //conectar
    int descriptor = socket(AF_UNIX, SOCK_STREAM, 0);

    struct sockaddr_un * datosSocket = malloc(sizeof(struct sockaddr_un));

    datosSocket->sun_family = AF_UNIX;
    strcpy(datosSocket->sun_path, path_socket_unix);

    connect(descriptor, (struct sockaddr *) datosSocket, strlen(path_socket_unix) + 1 + sizeof datosSocket->sun_family);


    enviarDatos(descriptor);

    }
    return 0 ;
}

void enviarDatos(int descriptor)
{
    int c,i;
    char cadena[30];

    while(strcmp(cadena,"fin") != 0){
        while ((c = getchar()) != '\n')    {
            cadena[i] = c;
            i++;
        }


        send(descriptor, cadena, strlen(cadena)+1, 0);

    }
}
